<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="{__ADMIN_PATH}/assets/images/favicon.ico" rel="icon">
<title>后台登录</title>
<link rel="stylesheet" href="{__ADMIN_PATH}/assets/libs/layui/css/layui.css?v={$version}"/>
<link rel="stylesheet" href="{__ADMIN_PATH}/assets/module/admin.css?v={$version}"/>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="{__ADMIN_PATH}/assets/css/login.css?v={$version}">
<script>
    if (window != top) {
        top.location.replace(location.href);
    }
</script>
</head>
<body>
<div class="login-wrapper">
    <div class="layui-form">
        <h2>用户登录</h2>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-username"></i>
            <input class="layui-input" name="username" placeholder="请输入登录账号" autocomplete="off"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-password"></i>
            <input class="layui-input" name="password" placeholder="请输入登录密码" type="password"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
        {if $is_vertify ==1}
          <div class="layui-form-item layui-input-icon-group login-captcha-group">
              <i class="layui-icon layui-icon-auz"></i>
              <input class="layui-input" name="code" placeholder="请输入验证码" autocomplete="off"
                     lay-verType="tips" lay-verify="required" required/>
              <img class="login-captcha" src="{:url('/login/captcha')}" id="LAY-user-get-vercode">
          </div>
        {/if}
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-filter="loginSubmit" lay-submit>登录</button>
        </div>
        <div class="layui-form-item login-oauth-group text-center" style="display:none;">
            <a href="javascript:;"><i class="layui-icon layui-icon-login-qq" style="color:#3492ed;"></i></a>&emsp;
            <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat" style="color:#4daf29;"></i></a>&emsp;
            <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo" style="color:#CF1900;"></i></a>
        </div>
    </div>
</div>
{include file="public/footer"/}
<script>
layui.use(['layer', 'form'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    form.render();//更新渲染
    $(document).keydown(function(event){
      if(event.keyCode ==13){
        $('div button[lay-filter=loginSubmit]').trigger('click');
      }
    });

    // 表单提交
    form.on('submit(loginSubmit)', function (obj) {
        //请求登入接口
        $.ajax({
          url: "{:url('/login/index')}",
          data: obj.field,
          type: "POST",
          dataType: "json",
          success: function(res){
            if (0 === res.code) {
              //登入成功的提示与跳转
              layer.msg(res.msg, {
                offset: '15px',
                icon: 1,
                time: 1000
              }, function(){
                window.location.href = res.data;//后台主页
              });
            } else {
              $('#LAY-user-get-vercode').trigger('click');
              layer.msg(res.msg, {offset: '15px',icon: 5,time: 1000, title:false});
              return false;
            }
          },
          error : function() {
             layer.msg("未知错误，操作中断！", {offset: '15px',icon: 5,time: 1000, title:false});
          }
        });
    });

    // 图形验证码
    $('.login-captcha').click(function () {
        this.src = this.src + '?t=' + (new Date).getTime();
    });
});
</script>
</body>
</html>